//
//  SettingViewController.m
//  GameBoss
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SettingViewController.h"
#import "SettingCell.h"
#import "LoginViewController.h"
#import <ShareSDK/ShareSDK.h>

#import "EnterState.h"
#import "DataCache.h"
#import "UIImageView+WebCache.h"
#import "AboutUsViewController.h"
#import "collectViewController.h"
@interface SettingViewController ()
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSMutableArray *secArr;
@property (nonatomic, retain) NSMutableArray *imageArr;
@property (nonatomic, copy) NSString *imageUrl;

@end

@implementation SettingViewController
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [_tableView release];
    [_arr release];
    [_secArr release];
    [_imageArr release];
    [_imageUrl release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.secArr = [NSMutableArray arrayWithObjects:@"分享", @"我的收藏",@"关于我们",@"夜间模式",nil];
        self.arr = [NSMutableArray arrayWithObjects:self.secArr, nil];
        self.imageArr = [NSMutableArray arrayWithObjects:@"04392ee6af4a1c61d6c3760119eaec50",@"6d4f62ae20eebc070e362238cf536f8c",@"wode" ,@"yejian", nil];
        self.title = @"设置";
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64) style:(UITableViewStyleGrouped)];
//#pragma mark 设置透明
//    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    [_tableView release];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.scrollEnabled = NO;
    
#pragma mark 夜间判断
    if ([NightMode shareNightMode].isNight) {
        [[NightMode shareNightMode] loadNightModeInfoFormDisk];
    }
    
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

//五个模块
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (!cell) {
        cell = [[[SettingCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:reuse] autorelease];
    }if (indexPath.section == 3){
        if ([NightMode shareNightMode].isNight) {
            cell.secImage.image = [UIImage imageNamed:@"rijiantaiyang"];
            cell.secLabel.text = @"日间模式";
        }else{
            cell.secImage.image = [UIImage imageNamed:@"yejian"];
            cell.secLabel.text = @"夜间模式";
        }
    }else{
        cell.secLabel.text = self.secArr[indexPath.section];
        cell.secImage.image = [UIImage imageNamed:self.imageArr[indexPath.section]];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#pragma mark 登录友盟
     if (indexPath.section == 0){
        NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ShareSDK" ofType:@"jpg"];
        //1、构造分享内容
        id<ISSContent> publishContent = [ShareSDK content:@"GameBoss"
                                           defaultContent:@"分享成功"
                                                    image:[ShareSDK imageWithPath:imagePath]
                                                    title:@"分享"
                                                      url:@"http://www.mob.com"
                                              description:@"这是一条演示信息"
                                                mediaType:SSPublishContentMediaTypeNews];
        //1+创建弹出菜单容器（iPad必要）
        id<ISSContainer> container = [ShareSDK container];
        [container setIPadContainerWithView:self.view arrowDirect:UIPopoverArrowDirectionUp];
        
        //2、弹出分享菜单
        [ShareSDK showShareActionSheet:container
                             shareList:nil
                               content:publishContent
                         statusBarTips:YES
                           authOptions:nil
                          shareOptions:nil
                                result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                    
                                    //可以根据回调提示用户。
                                    if (state == SSResponseStateSuccess)
                                    {
                                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                                        message:nil
                                                                                       delegate:self
                                                                              cancelButtonTitle:@"OK"
                                                                              otherButtonTitles:nil, nil];
                                        [alert show];
                                        [alert release];
                                    }
                                    else if (state == SSResponseStateFail)
                                    {
                                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                                        message:[NSString stringWithFormat:@"失败描述：%@",[error errorDescription]]
                                                                                       delegate:self
                                                                              cancelButtonTitle:@"OK"
                                                                              otherButtonTitles:nil, nil];
                                        [alert show];
                                        [alert release];
                                    }
                                }];
    }else if (indexPath.section == 1)
    {
        collectViewController *collectVC = [[collectViewController alloc] init];
        [self.navigationController pushViewController:collectVC animated:YES];
        [collectVC release];
    } else if (indexPath.section == 2)
    {
        AboutUsViewController *aboutUs = [[AboutUsViewController alloc] init];
        aboutUs.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:aboutUs animated:YES];
        [aboutUs release];
    }else if (indexPath.section == 3)
    {
#pragma mark 夜间模式控制按钮
        [NightMode shareNightMode].isNight = ![NightMode shareNightMode].isNight;
        [[NightMode shareNightMode] saveNightModeInfoToDisk];
        [self.tableView reloadData];
    }
}
/******宽度********/
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return Screen.height*0.09;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5;
}


#pragma mark 选取白黑两种模式
- (void)setNightDayModel {
    [NightManager setBackgroundColorWithView:self.view];
    [NightManager setBackgroundColorWithView:self.tableView];

}

- (void)setLightDayModel {
    [NightManager setBackgroundColorWithView:self.view];
    [NightManager setBackgroundColorWithView:self.tableView];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
